package com.dengbw.systemtransfer.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author dengbw
 * @date 2021/8/24 1:23 下午
 */
@Data
@SuppressWarnings("unused")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> {

    private boolean success;
    private int code;
    private String msg;
    private T data;

    public Result(boolean success, int code) {
        this.setSuccess(success);
        this.setCode(code);
    }

    public Result(boolean success, int code, T data) {
        this.setSuccess(success);
        this.setCode(code);
        this.setData(data);
    }

    public Result(boolean success, int code, String msg) {
        this.setSuccess(success);
        this.setCode(code);
        this.setData(data);
        this.setMsg(msg);
    }

    public static <T> Result<T> success() {
        return new Result<>(true, 200);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(true, 200, data);
    }

    public static <T> Result<T> fail(HttpStatus httpStatus) {
        return new Result<>(false, httpStatus.code(), httpStatus.reasonPhraseUS());
    }

    public static <T> Result<T> fail(HttpStatus httpStatus, String msg) {
        return new Result<>(false, httpStatus.code(), msg);
    }
}
